package com.bsj.power.pls.file.saveData;

import com.alibaba.fastjson.JSON;
import com.bsj.getFile.GetFileAction;
import com.bsj.getFile.def.ResultObj;
import com.bsj.getFile.motion.CheckData;
import com.bsj.power.common.constant.UWBPosConstant;
import com.bsj.power.common.def.vo.pls.httpVo.HttpTagPosVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.bsj.JedisClusterBSJ;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description 标签设备的原始数据存储
 * @time 2024/5/21 16:03
 */
@Component
public class SaveDataBaseUntil {

    private GetFileAction getFileAction;

    @Autowired
    public JedisClusterBSJ jedisClusterBSJ;

    public void init() {
        getFileAction = new GetFileAction(new CheckData() {
            @Override
            public ResultObj check(byte[] bytes) {
                ResultObj resultObj = new ResultObj();
                String data = new String(bytes);
                HttpTagPosVO posData = JSON.parseObject(data, HttpTagPosVO.class);
                resultObj.setFlag(true);
                resultObj.setContext(bytes);
                resultObj.setId(posData.getSn());
                return resultObj;
            }
        }, jedisClusterBSJ);
        getFileAction.start(UWBPosConstant.UWB_BASE_ORIGINAL);
    }

    public void push(byte[] bytes) {
        getFileAction.pushData(bytes);
    }

}
